package cn.tannn.cat.file.server.init;

import cn.tannn.cat.file.sdk.core.OssCache;
import cn.tannn.cat.file.server.entity.FileStorageConfig;
import cn.tannn.cat.file.server.service.FileStorageConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * ftp 项目启动加载所有客户端连接信息
 *
 * @author lxw
 * @version V1.0
 * @date 2021/2/1
 **/

@Slf4j
@Component
public class FtpInit implements ApplicationRunner {

    /**
     * 存储配置
     */
    @Autowired
    private FileStorageConfigService fileStorageConfigService;


    @Override
    public void run(ApplicationArguments args) {
        List<FileStorageConfig> ftpConfig = fileStorageConfigService.findFtpConfig();
        ftpConfig.forEach(info -> OssCache.ftpConnectInfoCache.put(info.getId(), info.toFileStorage()));
    }
}
